<?php		
  require_once $_SERVER['DOCUMENT_ROOT'] . '/proyecto/clases/autoload.inc.php';		
  require_once ($_SERVER['DOCUMENT_ROOT'] .'/proyecto/modulos/informes/config/lang/eng.php');		
  require_once ($_SERVER['DOCUMENT_ROOT'] . '/proyecto/modulos/informes/tcpdf.php');		
  if (Zen::IniciarSesion())		
  {				
    $vigencia = stripslashes(htmlspecialchars(trim($_GET['vigencia'])));
     $rs = Zen::Consulta("SELECT  UPPER(CON.CON_RUT) AS RUT, 
	UPPER(CON.CON_NOMBRE) AS NOMBRE,
	UPPER(CON.CON_DIRECCION) AS DIRECCION, 
	UPPER(COM.COM_NOMBRE) AS COMUNA,
	UPPER(CON.CON_FONO) AS FONO,
	CASE WHEN CON.CON_VIGENCIA = 'T' THEN 'VIGENTE' ELSE 'NO VIGENTE' END AS ESTADO
		
FROM	CONVENIOS AS CON LEFT JOIN COMUNAS AS COM ON CON.COM_ID = COM.COM_ID
	
WHERE 	CON_VIGENCIA = '$vigencia';");
if($vigencia=='T') $vigencia='Vigente';
if($vigencia=='F') $vigencia='No Vigente';	

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Custom Header and Footer
 * @author Nicola Asuni
 * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
 * @link http://tcpdf.org
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
 * @since 2008-03-04
 */
class MYPDF extends TCPDF {
	public function Header() {
	    $fecha=date("d-m-Y H:i:s");
		$image_file = K_PATH_IMAGES.'logo.png';
		$this->Image($image_file, 10, 10, 15, '', 'PNG', '', 'T', false, 0, '', false, false, 0, false, false, false);
		$this->SetFont('times', 'B', 8);
        $this->SetXY(25,11);
        $this->Cell( 0, 0, 'Centro de Imagenología S.A.', 0, false, 'L', 0, '', 0, false, 'M', 'M');
        $this->SetXY(25,15);
        $this->Cell( 0, 0, 'Administración y Finanzas', 0, false, 'L', 0, '', 0, false, 'M', 'M');
        $this->SetXY(25,9.5);
        $this->Cell( 0, 0, $fecha, 0, false, 'R', 0, '', 0, false, 'M', 'M');
        $this->SetXY(25,14);
        $this->Cell( 0, 0, $_SESSION['usuario'], 0, false, 'R', 0, '', 0, false, 'M', 'M');
        $this->ln(4.5);
        $this->Cell(190, 0, 'Página '.$this->getAliasNumPage().' de '.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
	}
	public function Footer() {
	}
}
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 003');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setLanguageArray($l);
$pdf->SetFont('times', 'BN', 12);
$pdf->AddPage();
$txt = <<<EOD
Convenios
EOD;
$pdf->SetFont('times', 'B', 14);
$pdf->Write($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
$pdf->SetFont('times', 'U', 10);
$pdf->ln(10);
$pdf->SetFont('times', 'B', 8);
$html = <<<EOF
<hr width="635" />
<br/>
<table>
    <tr>
        <td width="60" align="center">R.U.T.</td>
        <td width="187" align="center">Nombre</td>
        <td width="187" align="center">Dirección</td>
        <td width="100" align="center">Comuna</td>
        <td width="100" align="center">Estado</td>
    </tr>
</table>
<hr width="635" />
EOF;
$pdf->writeHTML($html, true, false, false, false, '');
$pdf->SetFont('times', '', 8);
$pdf->ln(5);
foreach ($rs as $k => $record){
$pdf->Cell( 17, 0, $record['rut'], 0, false, 'C', 0, '', 0, false, 'M', 'M');
$pdf->Cell( 52.5, 0, $record['nombre'], 0, false, 'C', 0, '', 0, false, 'M', 'M');
$pdf->Cell( 52.5, 0, $record['direccion'], 0, false, 'C', 0, '', 0, false, 'M', 'M');
$pdf->Cell( 28.5, 0, $record['comuna'], 0, false, 'C', 0, '', 0, false, 'M', 'M');
$pdf->Cell( 28.5, 0, $record['estado'], 0, false, 'C', 0, '', 0, false, 'M', 'M');
$pdf->ln(5);
}
$html = <<<EOF
</br>
<hr width="635" />
EOF;
$pdf->writeHTML($html, true, false, false, false, '');
ob_end_clean();
$pdf->Output('r26.pdf', 'D');
} else {
    Zen::LogoutModulo();
}
?>